-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoiding direct BuildConfig
usage
#6517
Conversation
@@ -284,7 +264,6 @@ android { | |||
versionName "${versionMajor}.${versionMinor}.${versionPatch}${getGplayVersionSuffix()}" | |||
|
|||
resValue "bool", "isGplay", "true" | |||
buildConfigField "boolean", "ALLOW_FCM_USE", "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ALLOW_FCM_USE
is not used
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
object ConfigurationModule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a dedicated module to provide the abstractions for Config/BuildConfig
@@ -48,31 +48,32 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { | |||
@Inject lateinit var activeSessionHolder: ActiveSessionHolder | |||
@Inject lateinit var analyticsTracker: AnalyticsTracker | |||
@Inject lateinit var clock: Clock | |||
@Inject lateinit var actionIds: NotificationActionIds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the notification ids include the application package name which is now injected
e37cdb2
to
ce7b3f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice improvement. My 2 cents
fun providesBuildMeta() = BuildMeta() | ||
fun providesBuildMeta() = BuildMeta( | ||
isDebug = BuildConfig.DEBUG, | ||
sdkInt = Build.VERSION.SDK_INT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdkInt
is a bit out of scope for BuildMeta
object (I just see that BuildMeta
is not new, was not aware of this class before), since Build.VERSION.SDK_INT
have different values at runtime (and not at compile time). We have BuildVersionSdkIntProvider
on the SDK, and also AndroidVersionTestOverrider
(that looks a bit hacky, I would be happier to have a similar BuildVersionSdkIntProvider
) app side, which allow to do some test and overriding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very true, happy to swap out for the BuildVersionSdkIntProvider
or a :vector
version of the same class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used the existing provider 3bfe25a
data class BuildMeta( | ||
val sdkInt: Int = Build.VERSION.SDK_INT | ||
val isDebug: Boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to propagate isDebug
to submodules? I think if we chose the Debug
(resp Release
) buildType
, all the submodules will use the same buildType
, and so all BuildConfig.DEBUG
will have the same values for all modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use the BuildConfig
like you've mentioned, I would lean towards abstracting as it provides an entry point for testing, avoid modules needing to generate a BuildConfig
and will still work if we start to use pure kotlin modules.
From a build/architecture perspective, ideally variants would only exist at the Android application module level rather than leaking the concept of an element application into the library modules, this will mainly benefit compilation time of multiple variants as the modules will only need to be compiled once for all variants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points. Thanks!
@@ -81,7 +81,8 @@ class HomeActivityViewModel @AssistedInject constructor( | |||
private val analyticsStore: AnalyticsStore, | |||
private val lightweightSettingsStorage: LightweightSettingsStorage, | |||
private val vectorPreferences: VectorPreferences, | |||
private val analyticsTracker: AnalyticsTracker | |||
private val analyticsTracker: AnalyticsTracker, | |||
private val analyticsConfig: AnalyticsConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
analyticsConfig
appear to be unused, at least there is no other change form this file in GH interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's because the previous import has been replaced with an instance property of the same name import im.vector.app.config.analyticsConfig
-> private val analyticsConfig: AnalyticsConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, sure.
val DISMISS_ROOM_NOTIF_ACTION = "${buildMeta.applicationId}.NotificationActions.DISMISS_ROOM_NOTIF_ACTION" | ||
val TAP_TO_VIEW_ACTION = "${buildMeta.applicationId}.NotificationActions.TAP_TO_VIEW_ACTION" | ||
val DIAGNOSTIC_ACTION = "${buildMeta.applicationId}.NotificationActions.DIAGNOSTIC" | ||
val PUSH_ACTION = "${buildMeta.applicationId}.PUSH" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these are not const val
anymore, I think the naming convention is not followed anymore here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | ||
* Util class for creating notifications. | ||
* Note: Cannot inject ColorProvider in the constructor, because it requires an Activity | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always a bit sad to see comment blocks vanish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to add back, although I'm not sure this comment block adds much?
- Note: Cannot inject ColorProvider in the constructor, because it requires an Activity
From what I can tell, this technically this isn't true, ColorProvider
has an application context injected (unless I've missed something 🤔 )
- Util class for creating notifications.
Could be avoided by renaming the file to NotificationFactory
or NotificationCreator
, which helps give the class clarity in its purpose (utility classes can be see as an anti pattern, although extensions get a free pass... 🙃 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this is old comment I think, you are right. Also I do not understand why this class has @Singleton
. And yes this would definitely needs a renaming. This class is maybe 6 or 7 years old :).
) | ||
|
||
@Provides | ||
fun providesVoipConfig() = VoipConfig( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 for splitting between several small config classes!
More remarks:
|
ahh I had only checked the vector module for the SDK config it depends if we want the values to be available for consumers of the library vs only us/source compilers, at the moment the artifact we release is always if we want to respect the debug config of the consumer app then the debug flag should be passed as part of the to help keep this PR smaller I would prefer to make the changes within the SDK as part of a separate PR but will fix the other points you've mentioned 👍 |
c16512d
to
987e03a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the update. one final remark
is EventSharedAction.OnUrlClicked -> { | ||
onUrlClicked(action.url, action.title) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange to see all those new lines. Is there a reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will revert, it looks like the autoformatting is doing something strange
I have the same issue when formatting this file on other branches
4c0dd91
to
7ed39ed
Compare
… opt out rather than relying on the package name to not be vector
…lds upon the application id
…build meta can't be injected before super application.onCreate
…instead of the sdk flag
7ed39ed
to
d1a63cc
Compare
SonarCloud Quality Gate failed. |
Type of change
Content
AnalyticsConfig
to theConfig
LocationConfig
,VoipConfig
,CryptoConfig
debug
andapplication id
to the injectableBuildMeta
Motivation and context
Fixes #6406
Avoids interacting directly with the
BuildConfig
outside the application level dagger module, this allows us to extract logic to modules which are relying on the build configurationScreenshots / GIFs
No UI changes
Tests
Tested devices